package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoRepairOrderImpotVO;
import com.yunxi.sto.pojo.StoRepairOrderVO;
import com.yunxi.sto.service.StoRepairOrderDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 车辆维修单 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-06-04
 */
@RestController
@RequestMapping("/admin/stoRepairOrder")
@Api(tags = "sto:repairorder", description = "车辆维修单接口")
public class StoRepairOrderController {
 private static final Logger logger = LoggerFactory.getLogger(StoRepairOrderController.class);

 @Autowired
 StoRepairOrderDubboService stoRepairOrderDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 @ApiImplicitParams({
         @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
         @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
 })
 public ApiResult page(StoRepairOrderVO stoRepairOrderVO, Integer pageNum, Integer pageSize) throws Exception {
  return ResponseUtil.ok(stoRepairOrderDubboService.findPageByVO(stoRepairOrderVO,pageNum,pageSize));
 }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 @ApiImplicitParam(paramType="query", name = "repairOrderId", value = "主键id", required = true, dataType = "String")
 public ApiResult load(String repairOrderId, @CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoRepairOrderDubboService.getById(repairOrderId));
 }

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody StoRepairOrderVO stoRepairOrderVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoRepairOrderDubboService.saveOrUpdate(stoRepairOrderVO);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/del")
 @ApiOperation(value = "作废")
 public ApiResult del(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoRepairOrderDubboService.delAndReset(list,1,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/reset")
 @ApiOperation(value = "恢复")
 public ApiResult reset(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
    stoRepairOrderDubboService.delAndReset(list,0,loginInfo.getUserCode());
    return ResponseUtil.ok("success");
 }

 @PostMapping("/batchStockOut")
 @ApiOperation(value = "批量转出库计划")
 public ApiResult batchStockOut(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoRepairOrderDubboService.batchStockInOut(list,1,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/batchStockIn")
 @ApiOperation(value = "批量转入库计划")
 public ApiResult batchStockIn(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoRepairOrderDubboService.batchStockInOut(list,0,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/batchComplete")
 @ApiOperation(value = "批量维修完成")
 public ApiResult batchComplete(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoRepairOrderDubboService.batchComplete(list,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @GetMapping("/export")
 @ApiOperation(value = "导出")
 public ApiResult export(StoRepairOrderVO stoRepairOrderVO) throws Exception {
  return ResponseUtil.ok(stoRepairOrderDubboService.export(stoRepairOrderVO));
 }

 @PostMapping("/import")
 @ApiOperation(value = "导入批量新增维修单")
 public ApiResult importBatch(@RequestBody List<StoRepairOrderImpotVO> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoRepairOrderDubboService.importBatch(list);
  return ResponseUtil.ok("success");
 }

}
